
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>用户管理</title>
    <%@include file="../../system/sys_common_head.jsp"%>
    <style type="text/css">
        .layui-table-cell{
            height: auto!important;
            white-space: normal;
        }
    </style>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="" lay-filter="searchForm" id="searchForm">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">姓名/身份证</label>
                    <div class="layui-input-inline">
                        <input type="text" name="nameOrIdCard" placeholder="" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">学校</label>
                    <div class="layui-input-inline">
                        <select name="schoolId" id="schoolId" lay-filter="schoolId">
                            <option value="">请选择</option>
                            <option value="1">江西赣州技师学院</option>
                            <option value="2">赣州农业学校</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">推送状态</label>
                    <div class="layui-input-inline">
                        <select name="status" id="status" lay-filter="status">
                            <option value="">请选择</option>
                            <option value="0">未推送</option>
                            <option value="1">已推送</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">缴费状态</label>
                    <div class="layui-input-inline">
                        <select name="jfstatus" id="jfstatus" lay-filter="jfstatus">
                            <option value="">请选择</option>
                            <option value="0">未缴费</option>
                            <option value="1">已缴费</option>
                            <option value="3">已取消</option>
                            <option value="4">已退费</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">专业</label>
                    <div class="layui-input-inline">
                        <select name="majorId" id="majorId" lay-filter="status">
                            <option value="">请选择</option>
                            <c:forEach var="major" items="${majorList}"><option value="${major.id}">${major.majorName}</option></c:forEach>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">学历</label>
                    <div class="layui-input-inline">
                        <select name="xueli" id="xueli" lay-filter="xueli">
                            <option value="">请选择</option>
                            <option value="初中">初中</option>
                            <option value="中专">中专</option>
                            <option value="高中">高中</option>
                            <option value="中技">中技</option>
                            <option value="职高">职高</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="margin-left: 50px;">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit="" lay-filter="preRegistration-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>

                </div>

                <%--<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="preRegistration-query">--%>
                    <%--<i class="layui-icon layui-icon-search"></i>--%>
                    <%--查询--%>
                <%--</button>--%>
                <%--<button type="reset" class="pear-btn pear-btn-md">--%>
                    <%--<i class="layui-icon layui-icon-refresh"></i>--%>
                    <%--重置--%>
                <%--</button>--%>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="preRegistration-table" lay-filter="preRegistration-table"></table>
    </div>
</div>
</body>
<script type="text/html" id="file-img">
    <img src="<%=request.getContextPath()%>/upload/{{d.imageUrl}}" style="width: 300px"/>
</script>
<script type="text/html" id="preRegistration-toolbar">
    <%--<button  class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">--%>
        <%--<i class="layui-icon layui-icon-add-1"></i>--%>
        <%--推送学生信息不缴费--%>
    <%--</button>--%>
    <%--<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">--%>
        <%--<i class="layui-icon layui-icon-delete"></i>--%>
        <%--删除--%>
    <%--</button>--%>
</script>

<script type="text/html" id="preRegistration-bar">
    <%--<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>--%>
    <%--</button>--%>
    <shiro:hasPermission name="editZYByLog">
    <button class="pear-btn  pear-btn-danger pear-btn-sm" lay-event="editZYByLog" title="管理员修改专业"><i class="layui-icon layui-icon-edit"></i>
    </button>
    </shiro:hasPermission>
    {{#if (d.status == '1') { }}

        {{# if(d.jfStatus == '0'){  }}
            未缴费
        {{# }else if(d.jfStatus == '1'){ }}
            已缴费
        {{# }else if(d.jfStatus == '3'){ }}
            已取消
        {{# }else if(d.jfStatus == '4'){ }}
            已退费
        {{# }else{ }}
            未知状态
        {{# } }}

        <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="showJF" title="查看缴费信息">查看</button>
    {{# }else{ }}
    <shiro:hasPermission name="billStudent">
        <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="addOne" title="推送学生进行缴费"><i class="layui-icon layui-icon-add-1"></i>
        </button>
    </shiro:hasPermission>
    <shiro:hasPermission name="editStudent">
        <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="editZY" title="修改专业"><i class="layui-icon layui-icon-edit"></i>
        </button>
    </shiro:hasPermission>



    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove" title="删除学生"><i class="layui-icon layui-icon-delete"></i>
    </button>

    {{# } }}
    <%--<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i>--%>
    <%--</button>--%>
</script>


<script>
    layui.use(['table', 'form', 'jquery','layer', 'util'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let layer = layui.layer;
        var util = layui.util;

        let MODULE_PATH = "/student/preregistration/";

        let cols = [
            [
                // {type: 'checkbox'},
                {field: 'id', title: 'ID',hide:true},
                {field: 'name', title: '姓名'},
                {field: 'idCard', title: '身份证号'},
                {field: 'xueli', title: '学历',hide:true},
                {field: 'schoolName', title: '报名学校',hide:true},
                {field: 'majorName', title: '报名专业'},
                {field: 'sex', title: '性别',hide:true},
                {field: 'bySchool', title: '毕业学校',hide:true},
                {field: 'graduateNo', title: '报名序号'},
                {field: 'score', title: '成绩',sort:true},
                {field: 'imageUrl', title: '分数截图',templet: "<div><img src=\"<%=request.getContextPath()%>/upload/{{d.imageUrl}}\" alt=\"\" style=\"width:80px; height:80px;\" onclick=\"showBigImage(this)\"\"></div>"},
                {field: 'status', title: '状态',templet:function(d){
                        if(d.status == 1){
                            return "成功";
                        }else{
                            return "未推送";
                        }}},
                {field: 'phone', title: '学生电话'},
                {field: 'pPhone', title: '家长电话'},
                {field: 'memo', title: '备注',edit: 'text'},
                {title: '操作', toolbar: '#preRegistration-bar', align: 'center', width: 160}
            ]
        ]

        table.render({
            elem: '#preRegistration-table',
            url: MODULE_PATH + 'list',
            page: true,
            cols: cols,
            skin: 'line',
            editTrigger: 'dblclick', //双击编辑
            toolbar: '#preRegistration-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        // 单元格编辑后的事件
        table.on('edit(preRegistration-table)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            // layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改值为：'+ util.escape(value));
            let loading = layer.load();
            $.ajax({
                url: MODULE_PATH + 'update',
                data: JSON.stringify({
                    id:data.id,
                    memo:value
                }),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    layer.close(loading);
                    if (result.code == 0) {
                        layer.msg(result.msg, {icon: 1, time: 3000});
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 3000});
                    }
                },error:function( e ){
                    layer.close(loading);
                    layer.msg("系统错误", {icon: 2, time: 3000});
                }
            })
        });

        table.on('tool(preRegistration-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'editZY') {
                window.editZY(obj);
            } else if (obj.event === 'editZYByLog') {
                window.editZYByLog(obj);
            } else if (obj.event === 'power') {
                window.power(obj);
            }else if(obj.event === 'addOne') {
                window.addOne(obj);
            }else if(obj.event === 'payOne'){

            }else if(obj.event === 'showJF'){
                window.showJF(obj);
            }
        });

        table.on('toolbar(preRegistration-table)', function (obj) {
            if (obj.event === 'add') {
                window.add(obj);
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        table.on('sort(preRegistration-table)', function (obj) {
            var data1 = form.val("searchForm");
            const obj2 = Object.assign(data1, obj);
            console.log(obj2)
            table.reload('preRegistration-table', {where: obj2})
        });


        form.on('submit(preRegistration-query)', function (data) {
            table.reload('preRegistration-table', {where: data.field})
            return false;
        });

        window.remove = function(obj){
            console.log(obj)
            layer.confirm('确定要删除该学生吗？', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();

                $.ajax({
                    url: MODULE_PATH + "remove/" + obj.data.id,
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 0) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })

            })
        }

        window.add = function (obj) {
            let data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            let ids = "";
            for (let i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);

            layer.confirm('确定要推送这些数据？', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "putStudents/" + ids,
                    dataType: 'json',
                    type: 'put',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 0) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                // obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        window.addOne = function( obj ){
            layer.confirm('是否推送该学生？', function(index){
                let loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "billStudent/" + obj.data['id'],
                    dataType: 'json',
                    type: 'put',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 0) {
                            layer.msg(result.msg, {icon: 1, time: 3000}, function () {});
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 3000});
                        }
                        layui.table.reload("preRegistration-table");
                    },error:function(){
                        layer.msg("系统错误", {icon: 2, time: 1000}, function () {});
                    }
                })
            });
        }

        window.showJF = function (obj) {
            layer.open({
                type: 2,
                title: '显示缴费信息',
                shade: 0.1,
                area: ['500px', '500px'],
                content: '<%=request.getContextPath()%>/student/prelog/preLogInfo?idCard='+ obj.data['idCard']
            });
        }

        window.editZY = function (obj) {
            layer.open({
                type: 2,
                title: '修改',
                shade: 0.1,
                area: ['500px', '500px'],
                content: MODULE_PATH + 'edit?id=' + obj.data['id']
            });
        }

        window.editZYByLog = function (obj) {
            layer.open({
                type: 2,
                title: '修改',
                shade: 0.1,
                area: ['500px', '500px'],
                content: MODULE_PATH + 'editByLog?id=' + obj.data['id']
            });
        }

        //显示大图片
        window.showBigImage = function (e) {
            console.log(e)
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                shadeClose: true, //点击阴影关闭
                area: ['600px', '600px'], //宽高
                content: "<img style='width: 100%' src=" + $(e).attr('src') + " />"
            });
        }

        form.on('select(schoolId)', function(data){
            initMajorBySchoolId($("#schoolId").val())
        });

        // 初始化专业
        window.initMajorBySchoolId = function(schoolId){
            $.ajax({
                url: '<%=request.getContextPath()%>/common/queryMajorBySchoolId',
                dataType: 'json',
                data:{schoolId:schoolId},
                type: 'get',
                success: function (result) {
                    var inHtml = "<option value=''>请选择</option>";
                    // majorList = result;
                    for(var i = 0;i < result.length; i++){
                        inHtml = inHtml+"<option value='"+result[i].id+"'>"+result[i].majorName+"</option>"

                    }
                    $("#majorId").html(inHtml);
                    form.render('select'); //刷新select选择框渲染
                }
            })
        }

        window.refresh = function () {
            table.reload('preRegistration-table');
        }
    })
</script>
</html>